package com.service.other;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class ServerConfig {
	public String server_ip = "127.0.0.1";
	public int server_port = 7001;
	public String webservice_server_ip = "127.0.0.1";
	public int webservice_server_port = 7001;
	public int frame_size = 512;
	public String db_driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	public String db_url="jdbc\\:sqlserver\\://192.168.10.8\\:1433;databaseName\\=ES_DEV";
	public String db_user="dev_user";
	public String db_password="hh123456";
	public String api_baidukey="601bcb4d3813622e97069bde8e62c1b9";
	public String gps_savepath="gpsdata";
	public String log_savepath="logs";
	public String hook_savepath = "hookdata";
	public String pwd_savepath = "password";
	public String debug_savepath = "debug";
	/**
	 * 上下班定时器默认延长10分钟
	 */
//	public int delayTime = 10;
	/**
	 * 检查作业遍数时，当前车辆距离路段检测点的误差距离默认15米
	 */
	public double checkPointDistance = 15;
	/**
	 * 垃圾装卸点范围(垃圾称重)
	 */
	public double garbageCollectionDistance = 15;
	/**
	 * 收集点半径(车辆报警)
	 */
	public double collectionDistance = 15;
	/**
	 * 离线报警时长, 超过该时长, 认为车辆离线
	 */
	public int offLineTime = 30;
	/**
	 * 作业遍数统计百分比
	 */
	public int workTimesPercent = 100;
	/**
	 * 私钥
	 */
	public String license_key = "";
	/**
	 * 垃圾箱距离垃圾处理场半径
	 */
	public double garbageDisposalSiteDistance = 100;
	/**
	 * 太仓公司code
	 */
	public String jstscode="048";
	private String configPath = "config/config.ini";
	private static ServerConfig config = new ServerConfig();
	/**
	 * 最新gps数据与上一条gps数据间隔（秒），为了计算gps
	 */
	public long intervaltime=120;
	/**
	 * 油感突升阀值
	 */
	public double oilJump=-1;
	/**
	 * 油感突降阀值
	 */
	public double oilDump=5;
	/**
	 * 连续超阀值数量
	 */
	public int thresholdNum=2;
	/**
	 * 油量突变标定值（work计算用）
	 */
	public int oliEx = 5;

    public static ServerConfig instance() {
        return config;
    }
	
	public ServerConfig() {
		init();
    }

	public void init() {
		try {
			Properties prop = new Properties();
			InputStreamReader input = new InputStreamReader(new FileInputStream(configPath),"gbk");
			prop.load(input);
			server_ip = prop.get("server.ip").toString();
			server_port = Integer.parseInt(prop.get("server.port").toString());
			frame_size = Integer.parseInt(prop.get("frame.size").toString());
			db_driver = prop.get("db.driver").toString();
			db_url = prop.get("db.url").toString();
			db_user = prop.get("db.user").toString();
			db_password = prop.get("db.password").toString();
			api_baidukey = prop.get("api.baiduKey").toString();
			gps_savepath = prop.get("gps.savepath").toString();
			log_savepath = prop.get("log.savepath").toString();
			hook_savepath = prop.getProperty("hook.savepath").toString();
			pwd_savepath = prop.getProperty("pwd.savepath").toString();

			checkPointDistance = Double.valueOf(prop.getProperty("checkpointdistance"));
			garbageCollectionDistance = Double.valueOf(prop.getProperty("garbagecollectiondistance"));
			collectionDistance = Double.valueOf(prop.getProperty("collectiondistance"));
			offLineTime = Integer.valueOf(prop.getProperty("offlinetime"));
			workTimesPercent = Integer.valueOf(prop.getProperty("worktimespercent"));
			if (workTimesPercent > 100)
				workTimesPercent = 100;
			
			webservice_server_ip = prop.get("noticeMessage.webservice.server.ip").toString();
			webservice_server_port = Integer.parseInt(prop.get("noticeMessage.webservice.server.port").toString());
			garbageDisposalSiteDistance = Double.valueOf(prop.getProperty("garbageDisposalSiteDistance"));
			intervaltime = Long.parseLong(prop.getProperty("intervaltime")) * 60;
			oilJump= Double.valueOf(prop.getProperty("oilJump"))/100.00;
			oilDump=Double.valueOf(prop.getProperty("oilDump"))/100.00;
			thresholdNum=Integer.valueOf(prop.getProperty("thresholdNum"));
		} catch (IOException e) {
			Logger.err(e);
		}
	}
}
